package cn.edu.zafu.bigdata.zqt.UDP;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.SimpleTimeZone;

public class Server {
    public static void main(String[] args) throws IOException  {
        DatagramSocket socket=new DatagramSocket(9876);
        byte[] buf=new byte[256];
        while (true){
            DatagramPacket packet=new DatagramPacket(buf,buf.length);
            socket.receive(packet);
            String dString=new SimpleDateFormat("yyyy-MM-ddHH:mm:ss").format(new Date());

            InetAddress address=packet.getAddress();
            int port=packet.getPort();
            String capitalizedSentence=dString;
            buf=capitalizedSentence.getBytes();
            packet=new DatagramPacket(buf,buf.length,address,port);
            socket.send(packet);
        }
    }
}
